In [47]:
import pandas as pd
import numpy as np
import plotly.express as px
import seaborn as sns
import matplotlib.pyplot as plt
from fbprophet import Prophet
In [ ]:
 
In [4]:
dataset_url="https://raw.githubusercontent.com/datasets/covid-19/master/data/countries-aggregated.csv"
df=pd.read_csv(dataset_url)
df = df[df['Confirmed']>0]
df.head()
Out[4]:
Date Country Confirmed Recovered Deaths
33 2020-02-24 Afghanistan 1 0 0
34 2020-02-25 Afghanistan 1 0 0
35 2020-02-26 Afghanistan 1 0 0
36 2020-02-27 Afghanistan 1 0 0
37 2020-02-28 Afghanistan 1 0 0
In [5]:
fig=px.choropleth(df,locations='Country',locationmode='country names',color='Confirmed'
                 ,animation_frame='Date')
fig.update_layout(title_text='Global spread of COVID-19')
fig.show()
In [6]:
fig = px.choropleth(df,locations="Country",locationmode='country names',color='Deaths',animation_frame='Date')
fig.update_layout(title_text='Global Deaths of COVID-19')
fig.show()
In [7]:
fig = px.choropleth(df,locations="Country",locationmode='country names',color='Recovered',animation_frame='Date')
fig.update_layout(title_text='Global Recovered of COVID-19')
fig.show()
In [58]:
def visualizer(df,lockdown_start_date,lockdown_end_date,cases):
    print("VISUALIZER")
    print()
    print(df.head())
    print()
    print(df.tail())
    st = ""
    if cases == "Confirmed":
        st = "Infection Rate"
    if cases == "Deaths":
        st = "Death Rate"
    if cases == "Recovered":
        st = "Recovered Rate"
    df[st] = df[cases].diff()
    df = df[df[st]>0]
    
    fig=px.line(df,x="Date",y=st)
    fig.add_shape(dict(type="line",x0=lockdown_start_date,y0=0,x1=lockdown_start_date,y1=df[st].max(),line=dict(color="red",width=2)))
    fig.add_annotation(dict(x=lockdown_start_date,y=df[st].max(),text='starting date of the lockdown'))
    fig.add_shape(dict(type='line',x0=lockdown_end_date,y0=0,x1=lockdown_end_date,y1=df[st].max(),line=dict(color="red",width=2)))
    fig.add_annotation(dict(x=lockdown_end_date,y=df[st].max(),text="lockdown end date"))
    fig.show()
    
    print("Maximum "+st+" till now is ",df[st].max())
    df = df.dropna()
    df = df.drop(st,axis=1)
    df.groupby("Country").sum().plot.barh()
    
In [59]:
def predictor(df,cases):
    print("PREDICTOR")
    df = df.sort_values('Date')
    df = df[df[cases]>0]
    prophet_df = df[['Date',cases]]
    print(prophet_df.head())
    prophet_df = prophet_df.rename(columns={'Date':'ds',cases:'y'})
    m = Prophet()
    m.fit(prophet_df)
    future = m.make_future_dataframe(periods=365)
    forecast = m.predict(future)
    m.plot(forecast,xlabel='Date',ylabel=cases)
In [60]:
input_df = input("Enter country name")
lsd = input("lockdown start date")
led = input("lockdown end date")
cases = input("Enter case(Confirmed,Deaths or Recovered)")
visualizer(df[df["Country"]==input_df],lsd,led,cases)
predictor(df[df["Country"]==input_df],cases)
Enter country nameIndia
lockdown start date2020-03-24
lockdown end date2020-08-17
Enter case(Confirmed,Deaths or Recovered)Confirmed
VISUALIZER

             Date Country  Confirmed  Recovered  Deaths
19679  2020-01-30   India          1          0       0
19680  2020-01-31   India          1          0       0
19681  2020-02-01   India          1          0       0
19682  2020-02-02   India          2          0       0
19683  2020-02-03   India          3          0       0

             Date Country  Confirmed  Recovered  Deaths
19915  2020-09-22   India    5562663    4497867   88935
19916  2020-09-23   India    5646010    4587613   90020
19917  2020-09-24   India    5732518    4674987   91149
19918  2020-09-25   India    5818570    4756164   92290
19919  2020-09-26   India    5903932    4849584   93379
<ipython-input-58-8a751ed85f0b>:14: SettingWithCopyWarning:


A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy

Maximum Infection Rate till now is  97894.0
PREDICTOR
             Date  Confirmed
19679  2020-01-30          1
19680  2020-01-31          1
19681  2020-02-01          1
19682  2020-02-02          2
19683  2020-02-03          3
INFO:fbprophet:Disabling yearly seasonality. Run prophet with yearly_seasonality=True to override this.
INFO:fbprophet:Disabling daily seasonality. Run prophet with daily_seasonality=True to override this.
In [ ]: